package com.koalacloud.koala.zhaikucloud.service.impl;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.GetResponse;
import co.elastic.clients.elasticsearch.core.IndexResponse;
import com.koalacloud.koala.zhaikucloud.entity.MallProduct;
import com.koalacloud.koala.zhaikucloud.service.ElasticSearchService;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author: GuoYang
 * @Description
 * @create 2022-05-05
 */
@Service
@RequiredArgsConstructor
public class ElasticSearchServiceImpl implements ElasticSearchService {

    private final ElasticsearchClient client;

    @Override
    public boolean createIndex(String indexName, Map<String, Object> columnMap) throws Exception {
        return false;
    }

    @Override
    public boolean existIndex(String index) throws Exception {
        return false;
    }

    @Override
    public boolean deleteIndex(String index) throws Exception {
        return false;
    }

    @Override
    public boolean addDocument(String index, String id, String content) throws Exception {
        System.out.println(client);
        MallProduct mallProduct = new MallProduct();
        mallProduct.setTitle("标题");
        mallProduct.setSellPoint("卖点");
        IndexResponse indexResponse = client.index(i -> i.index("product")
                .id("1")
                .document(mallProduct));
        return false;
    }

    @Override
    public boolean isExistsDocument(String index, String id) throws Exception {
        return false;
    }

    @Override
    public String getDocument(String index, String id) throws Exception {
        System.out.println(client);
        GetResponse<MallProduct> getResponse = client.get(g -> g
                .index("product")
                .id("1"), MallProduct.class);
        System.out.println(getResponse.source());
        return null;
    }

    @Override
    public boolean updateDocument(String index, String id, String content) throws Exception {
        return false;
    }

    @Override
    public boolean deleteDocument(String index, String id) throws Exception {
        return false;
    }

    @Override
    public boolean bulkRequest(String index, List<T> contents) throws Exception {
        return false;
    }

    @Override
    public List<Map<String, Object>> searchRequest(String index, String keyword) throws Exception {
        return null;
    }

    @Override
    public List<Integer> searchAllRequest(String index) throws Exception {
        return null;
    }
}
